package com.example.qx.adapter;

import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.qx.R;
import com.example.qx.lei.cos;
import com.example.qx.lei.liaotianrenheneirong;
import com.example.qx.lei.zhangmi;
import com.example.qx.lianxra.xiaoxijilu;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;

public class xiaoxiadapter extends RecyclerView.Adapter<xiaoxiadapter.xiaoxiHolder> {
  private Context context;
  private zhangmi zhangmi= com.example.qx.lei.zhangmi.getInstance();
  private List<xiaoxijilu> list;
  public xiaoxiadapter(List<xiaoxijilu> list, Context context){
      this.context=context;
      this.list=list;
  }
    @NonNull
    @Override
    public xiaoxiadapter.xiaoxiHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_xiaoxi,parent,false);
        return new xiaoxiadapter.xiaoxiHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull xiaoxiadapter.xiaoxiHolder holder, int position) {
               cos cos =new cos();
      xiaoxijilu liaotianrenheneirong=list.get(position);
               holder.textView1.setText(liaotianrenheneirong.getNeirong());


                     if(!Objects.equals(liaotianrenheneirong.getTouxiang(), "s")&&(!Objects.equals(liaotianrenheneirong.getTouxiang(), ""))){

                             String b=String.valueOf(liaotianrenheneirong.getId());
                             b=b+"tx";
                             File filee=context.getDir("youqishuju",context.MODE_PRIVATE);
                             String abc= filee.getAbsolutePath();
                             File filel=new File(abc+"/"+b);
                             if(!filel.exists())
                                 cos.get(b,context);
                             Bitmap bitmap= BitmapFactory.decodeFile(abc+"/"+b);
                             if(liaotianrenheneirong.getId()==zhangmi.getZhang())
                             {
                                 holder.imageView.setImageBitmap(bitmap);
                                 holder.imageView.setVisibility(View.VISIBLE);
                                 holder.textView1.setBackgroundColor(Color.GREEN);
                             }
                             else
                             {
                                 holder.imageView1.setImageBitmap(bitmap);
                                 holder.imageView1.setVisibility(View.VISIBLE);
                                 holder.textView1.setBackgroundColor(Color.WHITE);
                             }

                          }




    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public static class xiaoxiHolder extends RecyclerView.ViewHolder{

       private ImageView imageView,imageView1;
       private TextView textView1;
        public xiaoxiHolder(@NonNull View v) {
            super(v);
             imageView=v.findViewById(R.id.faqiren);
             imageView1=v.findViewById(R.id.jiesouren);
             textView1=v.findViewById(R.id.liantianneirong);
        }
    }
}
